import CommonAction from "../../../../../actions/common";
import {COMMON} from "../../../../../unit/util";

export default class HeaderAction extends CommonAction {
    constructor(comp) {
        super();
        this.comp = comp;
        this.dispatchType = 'staffCom/getStaffFlowInfo'; //查询数据用到
    }

    getPostData = () => {
        let {advObj, searchVal, pageInfo} = this.comp.state;
        let index = 7;
        let bemonth = ''
        let enmonth = ''
        if(advObj.rangeDate[0] && advObj.rangeDate[0].slice(6, 7) === '-'){
            index = 5
            bemonth = '0' + advObj.rangeDate[0].slice(5, 6)
            enmonth = '0' + advObj.rangeDate[1].slice(5, 6)
        }
        console.log(advObj.rangeDate[0].slice(6, 7))
        console.log("beginmonth: ",advObj.rangeDate[0] && advObj.rangeDate[0].slice(0, index) + bemonth);
        let pk_org = advObj.org && advObj.org.map(item => {
            return item.refpk
        }) 
        let pk_psncl = advObj.psncl && advObj.psncl.map(item => {
            return item.refpk
        })

        return {
            beginmonth: (advObj.rangeDate[0] && advObj.rangeDate[0].slice(0, index)+ bemonth) || null,//	开始月份	string	yyyy-mm
            endmonth: (advObj.rangeDate[1] && advObj.rangeDate[1].slice(0, index)+ enmonth) || null,//	结束月份	string	yyyy-mm
            change: advObj.change,//	变动统计
            entrydimi: advObj.entrydimi,//	入离职统计
            pk_org: pk_org || null,//	组织	string	如果是从统计值穿透过来的,为统计值对应的pk_org,即部门主键
            pk_psncl: pk_psncl || null,//	人员类别	string
            pk_chgtype: advObj.pk_chgtype && advObj.pk_chgtype.refpk || null,//	变动类型	string
            pk_dimitype: advObj.pk_dimitype && advObj.pk_dimitype.refpk || null,//	离职类型	string
            pk_entrytype: advObj.pk_entrytype && advObj.pk_entrytype.refpk || null,//	入职类型	string
        }
    };

    clear = () => {
        let {props} = this.comp;
        let page = props.staffCom.page;
        // 根据页面 默认 变动统计/入离职统计
        let flag = page === COMMON.pageStaffChange;
        let advObj = {
            org: null, //组织
            psncl: null, //人员类别
            entrydimi: !flag, //入离职统计
            change: flag, //变动统计
            pk_chgtype: "", //变动类型
            pk_dimitype: "", //离职类型
            pk_entrytype: "", //入职类型
            rangeDate: [], //起止日期
        };
        this.updateState({advObj})
    };

    updateState = (obj) => {
        return new Promise(resolve => {
            this.comp.setState(obj, resolve);
        })
    }
}
